#
# Copyright Bjorn De Meyer 2007. Can be used freely under the zlib license.
# Various utility  functions
#

module Rogaru::Utility

	def self.used_memory()
		size = 0 
		count = 0 
		# GC.start
 		ObjectSpace.each_object do |o| 
# 			begin 
# 				size += Marshal.dump(o).size
# 			rescue 
# 			end
 			count+=1 
# 			o=nil 
 		end 		
		return [count, size] 
	end

	def self.screen_make(wide, high, fullscreen, title = "", bpp = 16, doublebuf = true) 
		flags  = [ Rubygame::HWSURFACE , Rubygame::ANYFORMAT ]
		flags << Rubygame::FULLSCREEN if fullscreen
		flags << Rubygame::DOUBLEBUF  if doublebuf
		begin
			screen = Rubygame::Screen.new( [640, 480], bpp, flags )
		rescue Rubygame::SDLError
			raise "Could not open screen."
		end
		screen.title = title unless title.nil? or title.empty? 
		return screen
	end 
	
	def self.event_setup(nomouse = false)
		queue   = Rubygame::EventQueue.new() { @autofetch = true }
		queue.ignore = [ Rubygame::MouseMotionEvent ] if nomouse
		return queue
	end

	def self.joystick_setup()
		joysticks = []
		stop = Rubygame::Joystick.num_joysticks - 1
		for joynum in 0..stop do
			puts "Setting up joystick: " + Rubygame::Joystick.get_name( joynum )
			joysticks[joynum] = Rubygame::Joystick.new(joynum)
		end
		return joysticks
	end

end


